﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ITAP.Core.Modelling.Primitives;

using ITAP.Core.Calculations;
using ITAP.Core.Modelling;

namespace ITAP.ContourBuilder.Components.Dimensions
{
    [Serializable]
    public abstract class Dimension : ContourComponent
    {
        public IEndedPrimitive EndedPrimitive
        {
            get
            {
                return this.Primitive as IEndedPrimitive;
            }
        }

        private bool changeTextDirection = false;

        public virtual bool ChangeTextDirection
        {
            get { return changeTextDirection; }
            set { changeTextDirection = value; }
        }

        private Font font;

        public Font Font
        {
            get { return font; }
            set { font = value; }
        }

        private string prefixSymbol;

        public string PrefixSymbol
        {
            get { return prefixSymbol; }
            set { prefixSymbol = value; }
        }

        public virtual string DimensionText
        {
            get { throw new NotImplementedException(); }
        }

        public virtual void Recalculate()
        {

        }

        public virtual void AcceptDimensionVisitor(IDimensionVisitor visitor)
        {
            throw new NotImplementedException();
        }

        public override bool CanSelectByPoint(ModelPoint point)
        {
            if (SimpleEqualProvider.IsEqual(point, this.textCenterPoint, this.textModelWidth / 2))
                return true;
            else
                return false;
        }


        public override void SelectByPoint(ModelPoint point)
        {
            if (this.CanSelectByPoint(point))
                this.selected = true;
        }

        public override bool IsComponentDotted
        {
            get
            {
                return false;
            }
        }

        public override System.Drawing.RectangleF BoundingBox
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public override void AcceptVisitor(IContourVisitor visitor)
        {
            visitor.Visit(this);
        }

        public override int Id
        {
            get
            {
                return -1;
            }
            set
            {
            }
        }

        public virtual ModelVector GetSizeLineNormal()
        {
            return this.Primitive.GetNormalLine(0.5);
        }

        public override bool IsPrimitiveDependsOnDisplayParameters
        {
            get
            {
                return true;
            }
        }

        protected ModelPoint textCenterPoint;
        /// <summary>
        /// Центральная точка надписи размера. Вычисляется в рендере размеров.
        /// </summary>
        internal ModelPoint TextCenterPoint
        {
            set { textCenterPoint = value; }
        }

        protected float textModelWidth;
        /// <summary>
        /// Ширина надписи размера в размерах модели. Вычисляется в рендере размеров.
        /// </summary>
        internal float TextModelWidth
        {
            set { textModelWidth = value; }
        }
    }
}
